www.gusucode.com > 地方成人教育中心整站源代码 1 > 地方成人教育中心整站源代码 1.0/manage/Admin_Back.asp

    <!--#include file="conn.asp"-->
<!--#include file="chkuser.asp"-->
<%

'检测文件是否存在
Function IsExists(filespec) 
	Dim fso
	Set fso = CreateObject("Scripting.FileSystemObject")
	If (fso.FileExists(server.MapPath(filespec))) Then
	IsExists = True
	Else
	IsExists = False
	End If
	Set fso=nothing
End Function
 
 '删除文件
Function delfile(path)
If IsExists(path)=True Then 
	set fso = server.CreateObject("Scripting.FileSystemObject")
	fso.DeleteFile(server.mappath(path))
	set fso = nothing
End If
End Function 


'access数据库备份恢复
function CopyTo(ByVal cFile,ByVal toFile,databasename)
	 cFile=Server.MapPath(cFile) '所要备份的文件
	 toFile=Server.MapPath(toFile) '备份文件
	 Dim cFso,cf
	 set cFso=Server.CreateObject("Scripting.FileSystemObject")
	 if cFso.fileexists(cFile) then
		  cFso.Copyfile cFile,toFile
		  response.write   "Access数据库操作成功!备份文件名称为"&databasename&".mdb"
	 else
	  	response.write cFile&"文件不存在!"
	 end if
end function

function handle(backup_type,operateid,databasename)
	if databasename="" then
		response.Write("请填写备份数据库名称")
		response.End()
	end if
	if backup_type="sql"  then
		if operateid=1 then
			  delfile("/backup/"&databasename&".dat")
			  SQL="backup   database   "&idea_7&"   to   disk='"&Server.MapPath("\backup")&"\"&databasename&".dat"&"'"   
			  set   conn=Server.createobject("adodb.connection")   
			  conn.open   "driver={SQL Server};Server="&idea_6&";uid="&idea_8&";pwd="&idea_9&""  
			  conn.execute   SQL   
			  'on   error   resume   next   
			  if   err<>0   then   
					response.write   "错误:"&err.Descripting   
			  else   
					response.write   "sql server数据库备份成功!备份文件名称为"&databasename  
			  end   if 
			  conn.close()
			  set conn=nothing  
		 elseif operateid=2 then
			  SQL="Restore   database   "&idea_7&"   from   disk='"&Server.MapPath("\backup")&"\"&databasename&".dat"&"'"   
			  set   conn=Server.createobject("adodb.connection")   
			  conn.open    "driver={SQL Server};Server="&idea_6&";uid="&idea_8&";pwd="&idea_9&""   
			  conn.execute   SQL   
			 ' on   error   resume   next   
			  if   err<>0   then   
					response.write   "错误:"&err.Descripting   
			  else   
					response.write   "sql server数据库恢复成功!备份文件名称为"&databasename&".dat"
			  end   if   
			  conn.close()
			  set conn=nothing
		 else
			  response.write   "错误操作!"
		 end if
	elseif backup_type="access"  then
		if operateid=1 then
			 call CopyTo(idea_10,"/backup/"&databasename&".mdb",databasename)
		elseif operateid=2 then
			call CopyTo("/backup/"&databasename&".mdb",idea_10,databasename)
		else
			response.write   "错误操作!"
		end if
	end if
end function


if request.QueryString("backup")="ok" then
	if idea_5="1" then
		call handle("sql",1,replace(trim(request.Form("databasename")),"'",""))
	else
		call handle("access",1,replace(trim(request.Form("databasename")),"'",""))
	end if
end if

if request.QueryString("restore")="ok" then
	if idea_5="1" then
		call handle("sql",2,replace(trim(request.Form("databasename")),"'",""))
		
	else
		
		call handle("access",2,replace(trim(request.Form("databasename")),"'",""))
	end if
end if

%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="copyright" content="Copyright 2008 dananshan.com" />
<meta name="Author" content="闪电文章管理系统技术支持---www.dananshan.com" />
<meta name="Keywords" content="闪电文章管理系统文章管理系统" />
<meta name="Description" content="闪电文章管理系统文章管理系统" />
<title>数据库操作</title>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<body>
    <div id="frame_Toolbar" class="toolbarBg"> <a href="javascript:self.history.back();" class="icoBtn_ct"><span class="btnIco btnBack"></span><span class="btnTxt">返回</span></a> <a href="javascript:self.location.reload();" class="icoBtn_ct"><span class="btnIco btnReload"></span><span class="btnTxt">刷新</span></a> <span class="split ftSplit" ></span>
      <div class="pageInfo right light_gray"></div>
    </div>
    <table class="cTable_2 table">
	<tr class="cTitle toolbarBg">
		<td width="25%"><div>备份与还原数据库</div></td>
		<td colspan="2"></td>
	</tr>
	<tr>
		<form  action="?backup=ok" method="post" >	
		<td class="tRight"><span class="forumrow">备份:</span></td>
		<td width="22%"><input name="databasename" type="text" value="<%=replace(date,"-","")%>" size="40"></td>
	    <td width="53%"><input type="submit" value="开始备份" class="button"></td>
		</form>
	</tr>
	<tr>
	  <form  action="?restore=ok" method="post">
      <td class="tRight"><span class="forumrow">还原:</span></td>
	  <td><input name="databasename" type="text" onFocus="this.value=''" value="请填写数据库备份文件的名称" size="40"></td>
      <td><input type="submit" value="开始还原" class="button"></td>
      </form>
	  </tr>
    </table>
    <div id="cEndToolbar" class="toolbarBg">
      <div class="caButCase">
	      <font style="color:red; font-size:12px">*注意:数据库备份文件存放于根目录下的backup;(请记住您的备份文件名称,以便恢复数据库时使用)</font>
      </div>
    </div>
</body>
</html>